﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;
using System.Collections.Generic;

namespace Caffeine.Core.Test.TestModel.PropertyRegistrations
{
    public class ModelForComputedPropertyTestB : ModelBase
    {
        private readonly ModelProperty<Int32> _propertyAInt32;
        private readonly ModelProperty<Nullable<Decimal>> _propertyADecimal;
        private readonly ModelProperty<String> _propertyBString;
        private readonly ModelProperty<Object> _propertyBObject;
        private readonly ModelProperty<Nullable<Double>> _propertyCDouble;
        private readonly ModelProperty<DateTime> _propertyCDateTime;

        public ModelForComputedPropertyTestB()
        {
            _propertyAInt32 = RegisterProperty<Int32>("PropertyAInt32");
            _propertyADecimal = RegisterComputedProperty<Nullable<Decimal>, Int32>("PropertyADecimal", ComputeDecimal, PropertyAInt32);
            _propertyBString = RegisterProperty<String>("PropertyBString");
            _propertyBObject = RegisterComputedProperty<Object, String>("PropertyBObject", ComputeObject, PropertyBString);
            _propertyCDouble = RegisterProperty<Nullable<Double>>("PropertyCDouble");
            _propertyCDateTime = RegisterComputedProperty<DateTime, Nullable<Double>>("PropertyCDateTime", ComputeDateTime, PropertyCDouble);
        }

        public ModelProperty<Int32> PropertyAInt32
        {
            get
            {
                return _propertyAInt32;
            }
        }

        public ModelProperty<Nullable<Decimal>> PropertyADecimal
        {
            get
            {
                return _propertyADecimal;
            }
        }

        public ModelProperty<String> PropertyBString
        {
            get
            {
                return _propertyBString;
            }
        }

        public ModelProperty<Object> PropertyBObject
        {
            get
            {
                return _propertyBObject;
            }
        }

        public ModelProperty<Nullable<Double>> PropertyCDouble
        {
            get
            {
                return _propertyCDouble;
            }
        }

        public ModelProperty<DateTime> PropertyCDateTime
        {
            get
            {
                return _propertyCDateTime;
            }
        }

        private static Nullable<Decimal> ComputeDecimal(IEnumerable<ModelProperty<Int32>> properties, Int32 newPropertyValue)
        {
            return newPropertyValue;
        }

        private static Object ComputeObject(IEnumerable<ModelProperty<String>> properties, String newPropertyValue)
        {
            return newPropertyValue;
        }

        private static DateTime ComputeDateTime(IEnumerable<ModelProperty<Nullable<Double>>> properties, Nullable<Double> newPropertyValue)
        {
            return new DateTime(2000 + (Int32)Math.Floor(newPropertyValue ?? 0), 1, 1);
        }
    }
}
